package cn.jwcat.controller;

import cn.jwcat.entity.Area;
import cn.jwcat.service.IAreaService;
import cn.jwcat.utils.result.Result;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import io.swagger.annotations.ApiOperation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 房区操作
 */
@RestController
@Transactional
@RequestMapping("/area")
public class AreaController {
    @Resource
    IAreaService areaService;

    @GetMapping
    @ApiOperation("获取房区的全部列表")
    public Result getList() {
        List<Area> list = areaService.list();
        return Result.success(list);
    }

    @PutMapping
    @ApiOperation("改变房区的启用状态")
    public Result changeState(@RequestBody Area area) {
        return areaService.changeState(area);
    }

    @GetMapping("/option")
    @ApiOperation("获取已启用的房区列表")
    public Result getTrueOption() {
        LambdaQueryWrapper<Area> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Area::getStatus, true);
        List<Area> list = areaService.list(queryWrapper);
        return Result.success(list);
    }

    @GetMapping("/options")
    @ApiOperation("获取房区状态")
    public Result getStatusOption() {
        LambdaQueryWrapper<Area> queryWrapper = new LambdaQueryWrapper<>();
        List<Area> list = areaService.list(queryWrapper);
        return Result.success(list);
    }
}
